package misp_backend.controller;

import misp_backend.config.AjaxResult;
import misp_backend.domain.Orderdetails;
import misp_backend.domain.Payment;
import misp_backend.service.OrderService;
import misp_backend.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private PaymentService paymentService;
    @PostMapping("/makeNewOrder")
    public AjaxResult makeNewOrder(@RequestBody List<Orderdetails> orderitem, @RequestParam Long tableId,@RequestParam int customerNum){
      return AjaxResult.success( orderService.createOrder(orderitem,tableId,customerNum));
    }
    @PostMapping("/makeNewOrder2")
    public AjaxResult makeNewOrder2(@RequestParam Long packageId, @RequestParam Long tableId,@RequestParam int customerNum){
        return AjaxResult.success( orderService.createOrderByPackage(packageId, tableId, customerNum));
    }
    public AjaxResult changtable(@RequestParam Long orderid,@RequestParam Long tableId){
        return AjaxResult.success(orderService.changtable(orderid, tableId));
    }
    @GetMapping("/listorder")
    public AjaxResult listorder(){
        return AjaxResult.success(orderService.listwithname());
    }

    @GetMapping("/payment")
    public AjaxResult payment(String ordernum){
        return  AjaxResult.success(paymentService.makepayment(ordernum));
    }
}
